/*
Do file to generate results published in JAAEA Paper titled
"Preferences for Pandemic Recovery Policies: Perspectives of Myanmar Agri-food System Participants"
By Maredia et al. (2022)

This do file generates results for Fig 1, Table 4 (shown in Appendix E), and Appendix C & D

*/


*****************************************************************
*****************************************************************
*	Figure 1. Standardized BW scores (descriptive result)		*
*****************************************************************
*****************************************************************

//use "C:\Users\maredia\OneDrive - Michigan State University\Documents\BAPSA\BWS\AEPP submission\R&R\Data submission\JAAEA_survey_respondents_data.dta" , clear

use "<directory path>\JAAEA_BWS_survey_data.dta" , clear

gen p1_best1 = 1 if q1_1 ==1
gen p1_best2 = 1 if q4_1 ==1
gen p1_best3 = 1 if q6_1 ==1
gen p1_worst1 = 1 if q1_1 ==4
gen p1_worst2 = 1 if q4_1 ==4
gen p1_worst3 = 1 if q6_1 ==4
gen p2_best1 = 1 if q2_1 ==1
gen p2_best2 = 1 if q3_1 ==1
gen p2_best3 = 1 if q6_2 ==1
gen p2_worst1 = 1 if q2_1 ==4
gen p2_worst2 = 1 if q3_1 ==4
gen p2_worst3 = 1 if q6_2 ==4
gen p3_best1 = 1 if q5_1 ==1
gen p3_best2 = 1 if q6_3 ==1
gen p3_best3 = 1 if q7_1 ==1
gen p3_worst1 = 1 if q5_1 ==4
gen p3_worst2 = 1 if q6_3 ==4
gen p3_worst3 = 1 if q7_1 ==4
gen p4_best1 = 1 if q3_2 ==1
gen p4_best2 = 1 if q4_2 ==1
gen p4_best3 = 1 if q5_2 ==1
gen p4_worst1 = 1 if q3_2 ==4
gen p4_worst2 = 1 if q4_2 ==4
gen p4_worst3 = 1 if q5_2 ==4
gen p5_best1 = 1 if q2_2 ==1
gen p5_best2 = 1 if q4_3 ==1
gen p5_best3 = 1 if q7_2 ==1
gen p5_worst1 = 1 if q2_2 ==4
gen p5_worst2 = 1 if q4_3 ==4
gen p5_worst3 = 1 if q7_2 ==4
gen p6_best1 = 1 if q1_2 ==1
gen p6_best2 = 1 if q3_3 ==1
gen p6_best3 = 1 if q7_3 ==1
gen p6_worst1 = 1 if q1_2 ==4
gen p6_worst2 = 1 if q3_3 ==4
gen p6_worst3 = 1 if q7_3 ==4
gen p7_best1 = 1 if q1_3 ==1
gen p7_best2 = 1 if q5_3 ==1
gen p7_best3 = 1 if q2_3 ==1
gen p7_worst1 = 1 if q1_3 ==4
gen p7_worst2 = 1 if q5_3 ==4
gen p7_worst3 = 1 if q2_3 ==4
recode p1_best1-p7_worst3 (.=0)
gen p1_best_count= p1_best1 + p1_best2 + p1_best3
gen p2_best_count= p2_best1 + p2_best2 + p2_best3
gen p3_best_count= p3_best1 + p3_best2 + p3_best3
gen p4_best_count= p4_best1 + p4_best2 + p4_best3
gen p5_best_count= p5_best1 + p5_best2 + p5_best3
gen p6_best_count= p6_best1 + p6_best2 + p6_best3
gen p7_best_count= p7_best1 + p7_best2 + p7_best3
gen p1_worst_count = p1_worst1 + p1_worst2 + p1_worst3
gen p2_worst_count = p2_worst1 + p2_worst2 + p2_worst3
gen p3_worst_count = p3_worst1 + p3_worst2 + p3_worst3
gen p4_worst_count = p4_worst1 + p4_worst2 + p4_worst3
gen p5_worst_count = p5_worst1 + p5_worst2 + p5_worst3
gen p6_worst_count = p6_worst1 + p6_worst2 + p6_worst3
gen p7_worst_count = p7_worst1 + p7_worst2 + p7_worst3

gen p1_bws = (p1_best_count - p1_worst_count)/3
gen p2_bws = (p2_best_count - p2_worst_count)/3
gen p3_bws = (p3_best_count - p3_worst_count)/3
gen p4_bws = (p4_best_count - p4_worst_count)/3
gen p5_bws = (p5_best_count - p5_worst_count)/3
gen p6_bws = (p6_best_count - p6_worst_count)/3
gen p7_bws = (p7_best_count - p7_worst_count)/3


bys resp_type: sum p1_bws-p7_bws   //Data for Figure 1 

//X**X**X**X**X**X**X**X**X**X**X**X**X**X**X**X**X**X**X**X**X**X**X**X//



*****************************************************************
*****************************************************************
*	Table 4 and Appendix E. Determinants of policy preferences 	*
*	by different agri-food system participants: Summary of 		*
*	marginal effects estimated based on the FML model			*

*	Also--Desriptive statistics in Appendix C and D				*
*****************************************************************
*****************************************************************


*************************
*************************
///Farmers
*************************
*************************


use "<directory path>\JAAEA_Covariates_farmers_with_SOP.dta", clear

//Descriptive statistics--Appendix C
sum resp_age youth male edu_0_prim edu_sec edu_gtsec hhsize land_own maize_area21 n_cellph hh_expd_phone landown_ltm disruption_23 kayah shan

//Descriptive statistics--Appendix D
sum input_price_inc f1a_prep f1b_input f1c_less  disruption_yes disruption_23 f1d_change f1e_labor f5_expect  f4_tsp f4_vt

//RPL model estimates for Table 4
//universal base-- p6 (improve transportation)
local outreg_filename "<directory path>\fmlogit_farmers_baseP6.xls"
estimates clear
outreg, clear

local reg_type fmlogit_baseP6
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta (male youth edu_sec edu_gtsec hhsize landown_ltm disruption_23 kayah) cluster(villageID)
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_baseP6_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta (male youth edu_sec edu_gtsec hhsize landown_ltm disruption_23 kayah) cluster(villageID)
margins, dydx(*) predict(outcome(P1_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_baseP6_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta (male youth edu_sec edu_gtsec hhsize landown_ltm disruption_23 kayah) cluster(villageID)
margins, dydx(*) predict(outcome(P2_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_baseP6_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta (male youth edu_sec edu_gtsec hhsize landown_ltm disruption_23 kayah) cluster(villageID)
margins, dydx(*) predict(outcome(P3_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_baseP6_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta (male youth edu_sec edu_gtsec hhsize landown_ltm disruption_23 kayah) cluster(villageID)
margins, dydx(*) predict(outcome(P4_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_baseP6_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta (male youth edu_sec edu_gtsec hhsize landown_ltm disruption_23 kayah) cluster(villageID)
margins, dydx(*) predict(outcome(P5_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_baseP6_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta (male youth edu_sec edu_gtsec hhsize landown_ltm disruption_23 kayah) cluster(villageID)
margins, dydx(*) predict(outcome(P6_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_baseP6_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta (male youth edu_sec edu_gtsec hhsize landown_ltm disruption_23 kayah) cluster(villageID)
margins, dydx(*) predict(outcome(P7_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append


*************************
*************************
// Retailers
*************************
*************************

clear
use "<directory path>\JAAEA_Covariates_inputRetailers_with_SOP.dta" 


//Appendix C -- Descriptive statistics
sum resp_age youth male edu_0_prim edu_sec edu_gtsec yrs_worked loc_urban loc_periurban loc_rural 
tab state_region

//Appendix D -- Descriptive statistics
sum g5_a-g5_i disruption_yes disruption_23 // disruptions experienced
sum g8_1-g8_6 received_support //recieved benefits past 12 months

//universal base-- p6 (improve transportation)
local outreg_filename "C:\Users\maredia\OneDrive - Michigan State University\Documents\BAPSA\BWS\Results\fmlogit_retailers_baseP6_Feb11.xls"
estimates clear
outreg, clear

local reg_type fmlogit_baseP6
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban disruption_23 received_support i.state_region) cluster( state_region)
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P1_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P1_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P2_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P2_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P3_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P3_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P4_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P4_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P7_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P7_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P5_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P5_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P6_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P6_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append


*************************
*************************
///Crop traders
*************************
*************************

use "<directory path>\JAAEA_Covariates_cropTraders_with_SOP.dta", clear

//Appendix C -- Descriptive statistics
sum resp_age youth male edu_0_prim edu_sec edu_gtsec yrs_worked loc_urban loc_periurban loc_rural 
tab1 sizeTercile state_region

//Appendix D -- Descriptive statistics
sum f5_a-f5_g disruption_yes disruption_23 //disruptions
sum f8_1-f8_5 received_support  //recieved benefits past 12 months


///RPL Model estimation -- Table 4

local outreg_filename "C:\Users\maredia\OneDrive - Michigan State University\Documents\BAPSA\BWS\Results\fmlogit_traders_baseP6_June17.xls"
estimates clear
outreg, clear

local reg_type fmlogit_baseP6
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P1_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P1_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P2_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P2_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P3_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P3_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P4_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P4_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P6_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P6_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P5_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P5_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P7_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P7_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append


*************************
*************************
///Rice Millers
*************************
*************************

clear
use "<Directory path>\JAAEA_Covariates_riceMillers_with_SOP.dta", replace

//Appendix C -- Descriptive statistics
sum resp_age youth male edu_0_prim edu_sec edu_gtsec yrs_worked loc_urban loc_periurban loc_rural
tab1 sizeTercile state_region

//Appendix D -- Descriptive statistics
sum i5a_closed-i5i_prices disruption_yes disruption_23  //disruption relation statistics
sum i9a_cash-i9e_extension received_support  //recieved benefits past 12 months


//FML model estimation -- Table 4
local outreg_filename "C:\Users\maredia\OneDrive - Michigan State University\Documents\BAPSA\BWS\Results\fmlogit_millers_baseP6_June13.xls"
estimates clear
outreg, clear

local reg_type fmlogit_baseP6
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P1_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P1_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P2_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P2_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P3_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P3_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P4_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P4_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P6_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P6_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P5_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P5_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

local reg_type fmlogit_P7_margeffect
fmlogit P6_corrRPL P1_corrRPL P2_corrRPL P3_corrRPL P4_corrRPL P5_corrRPL P7_corrRPL, eta ( male youth edu_sec edu_gtsec  yrs_worked loc_urban i.bus_size disruption_23 received_support i.state_region) cluster( state_region)
margins, dydx(*) predict(outcome(P7_corrRPL)) post
outreg2 using "`outreg_filename'", se dec(3) excel label(insert) cttop("`reg_type'") append

*************************
*************************
//End of do file
